package com.sky.controller.admin;

import com.sky.result.Result;
import com.sky.service.ReporService;
import com.sky.vo.OrderReportVO;
import com.sky.vo.SalesTop10ReportVO;
import com.sky.vo.TurnoverReportVO;
import com.sky.vo.UserReportVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;

@RestController
@RequestMapping("/admin/report")
@Api(tags = "页面统计图统计接口")
public class ReportController {

    @Autowired
    ReporService reporService;
    /**
     * 营业额接口
     * **/
    @ApiOperation("营业额接口")
    @GetMapping("/turnoverStatistics")
    public Result<TurnoverReportVO> turnoverStatistics(@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate begin,
                                                        @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
      TurnoverReportVO vo = reporService.turnoverStatistics(begin,end);
        return Result.success(vo);
    }
    /**
     * 用户统计
     * **/
    @ApiOperation("用户统计")
    @GetMapping("//userStatistics")
    public Result<UserReportVO> userStatistics(@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate begin,
                                                   @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
        UserReportVO vo =  reporService.userStatistics(begin,end);
        return Result.success(vo);
    }
    /**
     * 订单统计
     * */
    @ApiOperation("订单统计")
    @GetMapping("//ordersStatistics")
    public Result<OrderReportVO> ordersStatistics (@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate begin,
                                                   @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
        OrderReportVO vo  =  reporService.ordersStatistics(begin,end);
        return Result.success(vo);
    }
    /**
     * 销量排名
     * */
    @ApiOperation("销量排名")
    @GetMapping("/top10")
    public Result<SalesTop10ReportVO> top10(@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate begin,
                                           @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
        SalesTop10ReportVO vo = reporService.top10(begin,end);
        return Result.success(vo);
    }
}
